﻿Public Class dinners
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles GridView1.SelectedIndexChanged

    End Sub

    Public Function getImageSource(ByVal AverageRating As Object) As String
        '**this function calls two methods - the first to establish that the value return is not null, the second to return the correct rating image**'
        Dim Stars As Integer
        Dim filepath As String
        Stars = getAverageRating(AverageRating)
        filepath = getStars(Stars)
        Return filepath
    End Function

    Protected Function getAverageRating(ByVal AverageRating As Object) As Integer
        If AverageRating Is DBNull.Value Then
            AverageRating = 0
        Else
            Return CInt(AverageRating)
        End If
    End Function


    Protected Function getStars(ByVal Stars As Integer)
        Dim retVal As String
        Dim retValSecond As String
        retVal = "/Images/"

        If Not DBNull.Value.Equals(Stars) Then


            Select Case Stars



                Case Is = 0
                    retValSecond = "notRated1.jpg"
                    retVal = retVal + retValSecond
                    Return retVal
                Case Is = 1
                    retValSecond = "535px-1_stars_svg.png"
                    retVal = retVal + retValSecond
                    Return retVal
                Case Is = 2
                    retValSecond = "535px-2_stars_svg.png"
                    retVal = retVal + retValSecond
                    Return retVal
                Case Is = 3
                    retValSecond = "535px-3_stars_svg.png"
                    retVal = retVal + retValSecond
                    Return retVal
                Case Is = 4
                    retValSecond = "4-stars.png"
                    retVal = retVal + retValSecond
                    Return retVal
                Case Is = 5
                    retValSecond = "5-Stars.png"
                    retVal = retVal + retValSecond
                    Return retVal
            End Select

            Return retVal + "notRated1.jpg"
        End If
    End Function
End Class